package com.youka.bussiness.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youka.bussiness.dao.UserInfoMapper;
import com.youka.bussiness.dao.entity.UserInfo;
import com.youka.bussiness.service.req.UserWxAuthDto;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import com.youka.bussiness.common.bean.RestResp;
import com.youka.bussiness.common.base.BaseEntity;
import com.youka.bussiness.common.base.BaseController;
import com.youka.bussiness.service.UserInfoService;
import com.youka.bussiness.service.req.UserInfoReqDto;
import com.youka.bussiness.service.req.UserInfoUpdateDto;
import com.youka.bussiness.service.req.UserInfoPageDto;
import com.youka.bussiness.service.res.UserInfoDto;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.List;

import java.util.Map;

/**
 * 用户信息表 Controller
 *
 * @author lfc
 * @date 2024-06-30 16:47:28
 */
@Api(tags = "app-用户信息表")
@RestController()
@RequestMapping("/app/UserInfo")
public class UserInfoAppController extends BaseController{

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private UserInfoMapper userInfoMapper;
    @ApiOperation(value = "微信授权登录")
    @PostMapping(value = "/login")
    public RestResp login(@RequestBody UserWxAuthDto entity) {
        UserInfo dto = userInfoMapper.selectOne(new LambdaQueryWrapper<UserInfo>()
                .eq(UserInfo::getWxAuthId, entity.getCode()));
        return success(dto);
    }


    /**
     * 查询用户信息表详情
     */
    @ApiOperation(value = "获取用户信息表详情")
    @PostMapping(value = "/single")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询用户信息表详情", response = UserInfoDto.class)
    })
    public RestResp findUserInfoById(@RequestBody BaseEntity entity) {
            UserInfoDto dto = userInfoService.selectById(entity.getId());
        return success(dto);
    }

    /**
     * 查询用户信息表集合
     */
    @ApiOperation(value = "查询用户信息表集合")
    @PostMapping("/list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询用户信息表详情", response = UserInfoDto.class)
    })
    public RestResp listUserInfo(@RequestBody UserInfoReqDto userInfoPageDto) {
        List<UserInfoDto> list = userInfoService.selectByList(userInfoPageDto);
        return success().toAdminTree(list);
    }

    /**
     * 查询用户信息表分页
     */
    @ApiOperation(value = "查询用户信息表分页")
    @PostMapping("/page")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询用户信息表详情", response = UserInfoDto.class)
    })
    public RestResp pageUserInfo(@RequestBody UserInfoPageDto userInfoPageDto) {
        IPage<UserInfoDto> page = userInfoService.selectByPage(userInfoPageDto);
        return success().toAdminPage(page);
    }

    /**
     * 新增用户信息表
     */
    @ApiOperation(value = "新增用户信息表")
    @PostMapping("/add")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询用户信息表详情", response = RestResp.class)
    })
    public RestResp addUserInfo(@RequestBody UserInfoReqDto userInfoReqDto) {
        userInfoService.insert(userInfoReqDto);
        return success();
    }

    /**
     * 编辑用户信息表
     */
    @ApiOperation(value = "编辑用户信息表")
    @PostMapping("/update")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询用户信息表详情", response = RestResp.class)
    })
    public RestResp updateUserInfo(@RequestBody UserInfoUpdateDto userInfoReqDto) {
        userInfoService.update(userInfoReqDto);
        return success();
    }

    /**
     * 删除用户信息表主键
     */
    @ApiOperation(value = "删除用户信息表")
    @PostMapping("/delete")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询用户信息表详情", response = RestResp.class)
    })
    public RestResp delete(@RequestBody BaseEntity entity) {
        userInfoService.deleteById(entity.getId());
        return success();
    }
}
